/*
 * @Author: szx
 * @Date: 2022-02-23 12:12:08
 * @LastEditTime: 2022-02-23 12:31:52
 * @Description:
 * @FilePath: \leetcode\800-899\838\838.js
 */
/**
 * @param {string} dominoes
 * @return {string}
 */
 var pushDominoes = function (dominoes) {
    const arr = dominoes.split('');
    let l = -1,
        r = 0,
        n = dominoes.length ,
        left = 'L';
    while (r < n) {
        while (r < n && arr[r] == '.') {
            r++;
        }
        const right = r < n ? arr[r] : 'R';
        // LL和RR的情况
        if (left == right) {
            for (let i = l + 1; i < r; i++) {
                arr[i] = left;
            }
        }
        // LR的情况
        else if (left == 'R' && right == 'L') {
            let i = l + 1,
                j = r - 1;
            while (i < j) {
                arr[i++] = 'R';
                arr[j--] = 'L';
            }
        } //还有个else的情况，RL的情况，但这种情况就不用动了
        l = r;
        left = right;
        r = l + 1;
    }
    return arr.join('');
};
